package com.data.modules.demo;

import java.io.*;

public class Test {

    public static void main(String[] args) throws IOException {

        String path = "D:\\0614.txt";

        readCount(path,"AB");
    }

    public static void readCount(String path,String target) throws IOException {
        int count = 0;
        BufferedReader in = new BufferedReader(new InputStreamReader(new BufferedInputStream(new FileInputStream(path))));
        String line = null;
        StringBuffer source = new StringBuffer();
        while ((line = in.readLine()) != null){
            System.out.println("==line:"+line);
            if(source.length() > 0){
                //source <= target 则需要再读取一行再继续匹配
                source.append(line);
            }else {
                source = new StringBuffer(line);
            }

            //source > target
            while(source.length() > target.length()){
                System.out.println("==source:"+source);
                int idx = source.indexOf(target);
                if(idx >= 0){
                    //存在
                    count ++;
                    //剪接 字符串
                    line = source.substring(idx + target.length(),source.length());
                    source = new StringBuffer(line);
                }
            }

            //source <= target 则需要再读取一行再继续匹配
        }

        System.out.println("==count:"+count);
    }

}
